<?php
require_once ($_SERVER['DOCUMENT_ROOT'].'/global.php');
include_once ($_SERVER['DOCUMENT_ROOT'].'/PHPExcel/Classes/PHPExcel.php');
$objPHPExcel = new PHPExcel();
/*以下是一些设置 ，什么作者  标题啊之类的*/
$objPHPExcel->getProperties()->setCreator("www.evuan.com")
->setLastModifiedBy('DingJinBiao')
->setTitle("DingJinBiao")
->setSubject("DingJinBiao")
->setDescription("DingJinBiao")
->setKeywords("DingJinBiao")
->setCategory("DingJinBiao");
/////////////////////////////////////////////
$array = array();
$array = array_keys($_FILES);
$fileElementName = $array[0];
$callBack['msg'] = $callBack['error'] = '';

$uploadFile = $_FILES[$fileElementName]['tmp_name'];
$PHPExcel = new PHPExcel();

/**默认用excel2007读取excel，若格式不对，则用之前的版本进行读取*/
$PHPReader = new PHPExcel_Reader_Excel2007();
if(!$PHPReader->canRead($uploadFile)){
	$PHPReader = new PHPExcel_Reader_Excel5();
	if(!$PHPReader->canRead($uploadFile)){
		$callBack['msg'] = ''; $callBack['error'] = '数据格式错误';
		echo json_encode($callBack);
		exit;
	}
}
$PHPExcel = $PHPReader->load($uploadFile);
/**读取excel文件中的第一个工作表*/
$currentSheet = $PHPExcel->getSheet(0);
/**取得最大的列号*/
$allColumn = $currentSheet->getHighestColumn();
/**取得一共有多少行*/
$allRow = $currentSheet->getHighestRow();
/**从第二行开始输出，因为excel表中第一行为列名*/

function getColumnNumber($char){//根据列号获取列对应数字
	$varchar = 'A';
	for ($i=0; $i < 10000; $i++) {
		if ($varchar == $char) {
			break;
		}
		$varchar++;
	}
	return $i;
}
// 清空entry_log_auto
// echo date('Y-m-d H:i:s',strtotime('2023/3/5 19:23:19'));
// exit;
$sql = "TRUNCATE table entry_lend_record ";
$query = $mysqli->query($sql);

//导入借书记录
for ($i=3; $i <= $allRow; $i++) {
  $thisXueHao = trim($currentSheet->getCellByColumnAndRow(1,$i)->getCalculatedValue());
  $thisCe =  trim($currentSheet->getCellByColumnAndRow(3,$i)->getCalculatedValue());
  $sql = "INSERT into entry_lend_record (XueHao,Ce) values ('{$thisXueHao}','{$thisCe}') ";
  $query = $mysqli->query($sql);
}
// $ZhouYi = date("Y-m-d",strtotime("last Monday"));
// $sql = "INSERT into entry_record_auto (XueHao,RiQi,Duration) values ('1800094','{$ZhouYi}',2.3) ";
// $query = $mysqli->query($sql);
// $sql = "INSERT into entry_record_auto (XueHao,RiQi,Duration) values ('1800134','{$ZhouYi}',2.5) ";
// $query = $mysqli->query($sql);
echo json_encode($callBack);
exit;
?>
